package com.iplant.basic.controller.fmc;

import com.iplant.base.po.Pagination;
import com.iplant.base.po.ServiceResult;
import com.iplant.base.utils.RetCode;
import com.iplant.base.utils.annotation.trace.TraceAPI;
import com.iplant.base.utils.general.StringUtils;
import com.iplant.basic.controller.BasicController;
import com.iplant.basic.service.FMCService;
import com.iplant.basic.service.po.bms.BMSEmployee;
import com.iplant.basic.service.po.fmc.FMCShift;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.servlet.http.HttpServletRequest;
import java.util.List;


@RestController
@RequestMapping("/api/FMCShift")
public class FMCShiftController extends BasicController<FMCShift> {
	private static Logger logger = LoggerFactory.getLogger(FMCShiftController.class);


	public FMCShiftController() {
		super(FMCShift.class);
	}


	@Autowired
	FMCService mFMCService;

	/**
	 * 条件查询
	 */
	@TraceAPI("批量查询")
	@GetMapping("/ShiftAll")
	public Object ShiftAll(HttpServletRequest request) {
		Object wResult;
		try {
			BMSEmployee wLoginUser = GetSession(request);
			int wFactoryID = StringUtils.parseInt(request.getParameter("FactoryID"));
			int wWorkshopID = StringUtils.parseInt(request.getParameter("WorkshopID"));
			int wWorkAreaID = StringUtils.parseInt(request.getParameter("WorkAreaID"));
			int wStationID = StringUtils.parseInt(request.getParameter("StationID"));

			Pagination wPagination = GetPagination(request);

			ServiceResult<List<FMCShift>> wServiceResult =
					mFMCService.FMC_QueryShiftList(wLoginUser, wFactoryID,wWorkshopID,wWorkAreaID,wStationID, wPagination);


			if (StringUtils.isEmpty(wServiceResult.getFaultCode())) {
				wResult = GetResult(RetCode.SERVER_CODE_SUC, "", wServiceResult.Result, wPagination.getTotalPage());
			} else {
				wResult = GetResult(RetCode.SERVER_CODE_ERR, wServiceResult.FaultCode);
			}
		} catch (Exception ex) {
			logger.error(ex.toString());
			wResult = GetResult(RetCode.SERVER_CODE_ERR, ex.toString());
		}
		return wResult;
	}


}
